package io.springboot.jpa.examples.springbootjpaexamples.web.controller;

import io.springboot.jpa.examples.springbootjpaexamples.model.User;
import io.springboot.jpa.examples.springbootjpaexamples.service.UserService;
import io.springboot.jpa.examples.springbootjpaexamples.web.ResultMap;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yzc
 * @description
 * @date 2018/9/9
 */
@Controller
@RequestMapping("/users")
@RequiresRoles("admin")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/{id}")
    @ResponseBody
    @RequiresPermissions("users")
    public Object getOne(@PathVariable("id")String id) {
        User user = userService.getOne(Long.valueOf(id));
        return new ResultMap().ok().data(user);
    }


    @GetMapping(value = "/menus/{id}")
    @ResponseBody
    public Object getMenus(@PathVariable("id")String id) {
        return new ResultMap().ok().data(userService.getMenusByUser(Long.valueOf(id)));
    }
}
